<?php
namespace app\cms\controller;
use framework\ext\Check;
use framework\ext\Page;
/* *
 * 标签管理
 * */
class LabelController extends \app\base\controller\AdminController{
    //标签列表
    public function index(){
        $act = form('get.act');
        if($act == 'del'){
            $id = form('get.id',0,intval);
            $result =  model('label')->_delete(array('id' => $id));
            if($result){
                $this->jsonMsg('删除成功',1);
            }else{
                $this->jsonMsg($result);
            }
        }else{
            $page = form('get.page',0,intval);
            $this->list = model('label')->pager($page,20)->_select();
            $this->pager = $this->getPage(model('label')->pager);
            $this->display();
        }
    }

    //标签添加
    public function addChannel(){
        $this->fid = form('get.id',0,intval);
        $this->info = model('label')->_find(array('id'=>$this->fid),'title,es_order,es_where');
        $this->display();
    }

    //标签添加
    public function addContent(){
        $this->fid = form('get.id',0,intval);
        $this->special = model('special')->getClass(0);
        $this->info = model('label')->_find(array('id'=>$this->fid));
        $this->display();
    }
    
    //标签保存
    public function LableSave(){
        if($this->isPost()){
            $msg = Check::rule(array(check::must($_POST['title']),'标签名称必须填写'));
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            $fid = form('post.fid',0,intval);
            $data = form('post',array('fid'));
            $data['uptime'] = time();
            if($fid){
                $info = model('label')->_update($data,array('id' => $fid));
            }else{
                $info = model('label')->_update($data);
            }
            if($info){
                $this->jsonMsg('标签添加成功！请返回',1,url('label/index'));
            }else{
                $this->jsonMsg('标签添加失败！请返回');
            }
        }
    }

    //标签效果预览
    public function preview(){
        $fid = form('get.id',0,intval);
        $this->display();
    }
}